<?php

declare (strict_types=1);

namespace App\Model;

use Hyperf\Database\Model\Relations\BelongsTo;
use Hyperf\Database\Model\Relations\HasOne;

/**
 */
class ShopOrderReview extends Model
{
    public $timestamps = false;
    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'fly_shop_order_reviews';
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [];
    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */

    protected $casts = ['reviews_show'=>'array','reviewer'=>'string'];

    /**
     * 关联订单
     * @return HasOne
     */
    public function with_order()
    {
        return $this->hasOne(FlyOrder::class, 'order_id', 'order_id')
            ->with('with_products');
    }

    /**
     * 关联用户信息
     * @return BelongsTo
     */
    public function user_info()
    {
        return $this->belongsTo(AppUser::class, 'reviewer', 'id')->select(['nickname', 'id', 'username']);
    }

//    时间戳转日期
    public function getCreateTimeAttribute($value)
    {
        return date('Y-m-d H:i:s',$value);
    }
}